package com.kbbywyclient.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.kbbywyclient.R;
import com.kbbywyclient.data.entity.CreditCardTableMenu;
import com.kbbywyclient.ui.adapter.base.BaseLvAdapter;
import com.kbbywyclient.util.ViewUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Description:
 * Created by FHW
 * on 2017/4/10
 */

public class MenuInformationAdapter extends BaseLvAdapter<CreditCardTableMenu.PersonalInformationBean> {


    static class ViewHolder {
        @BindView(R.id.tv_content)
        TextView tv_content;
        @BindView(R.id.iv_check)
        ImageView iv_check;
        @BindView(R.id.rl_condition)
        RelativeLayout rl_condition;

        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

    public MenuInformationAdapter(Context context, int itemLayout, List<CreditCardTableMenu.PersonalInformationBean> list) {
        super(context, itemLayout, list);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        CreditCardTableMenu.PersonalInformationBean personalInformationBean = getItem(position);

        ViewHolder holder = null;
        if (convertView == null) {
            convertView = getItemView();
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        ViewUtils.setText(holder.tv_content, personalInformationBean.getName());

        if (personalInformationBean.isCheck()) {
            holder.iv_check.setVisibility(View.VISIBLE);
            holder.tv_content.setTextColor(getContext().getResources().getColor(R.color.color_14C095));
        } else {
            holder.iv_check.setVisibility(View.GONE);
            holder.tv_content.setTextColor(getContext().getResources().getColor(R.color.color_212121));
        }

        return convertView;
    }

}
